package com.songtech.dictionary.controller;

import com.songtech.base.common.BaseConstant;
import com.songtech.base.common.JsonResult;
import com.songtech.common.dictionary.bean.SysDictionary;
import com.songtech.common.dictionary.service.SysDictionaryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: RENTIE
 * Date: 2018-06-19 10:43
 */
@RestController
@RequestMapping("/dictionary")
public class SysDictionaryController {

    private final Logger logger = LoggerFactory.getLogger(SysDictionaryGroupController.class);

    @Autowired
    private SysDictionaryService sysDictionaryService;

    /**
     * 查询某厂家下的产品列表
     * @param dictgroupId 厂家分组id
     * @return
     */
    @RequestMapping(value = "/product" ,method = RequestMethod.GET)
    public JsonResult selectProduct(String dictgroupId){
        List<SysDictionary> list = null;
        try {
            list= sysDictionaryService.selectProduct(dictgroupId);

        } catch (Exception e) {
            logger.error("查询产品列表异常信息:"+e.getMessage(),e);
            return new JsonResult(list, BaseConstant.FAIL_CODE, BaseConstant.FAIL);
        }
        return new JsonResult(list, BaseConstant.SUCCESS_CODE, BaseConstant.SUCCESS);
    }

    /**
     * 查询某产品的所有型号
     * @param dictId
     * @return
     */
    @RequestMapping(value = "/version" ,method = RequestMethod.GET)
    public JsonResult selectVersion(String dictId){
        List<SysDictionary> list = null;
        try {
            list= sysDictionaryService.selectVersion(dictId);

        } catch (Exception e) {
            logger.error("查询型号列表异常信息:"+e.getMessage(),e);
            return new JsonResult(list, BaseConstant.FAIL_CODE, BaseConstant.FAIL);
        }
        return new JsonResult(list, BaseConstant.SUCCESS_CODE, BaseConstant.SUCCESS);
    }

    /**
     * 查询库房列表
     *
     * @return
     */
    @RequestMapping(value = "/store" ,method = RequestMethod.GET)
    public JsonResult selectstore(){
        List<SysDictionary> list = null;
        try {
            list= sysDictionaryService.selectStoreByCode(BaseConstant.DIC_STORE);

        } catch (Exception e) {
            logger.error("查询型号列表异常信息:"+e.getMessage(),e);
            return new JsonResult(list, BaseConstant.FAIL_CODE, BaseConstant.FAIL);
        }
        return new JsonResult(list, BaseConstant.SUCCESS_CODE, BaseConstant.SUCCESS);
    }
}
